﻿//公共调用工具
//本文件由：周博儒( ) 贺镇涛（2021300004071）负责
#include"Mathtoys.h"
#include"PublicMethod.h"
#include<fstream>
#include<string>
#include<iostream>
#include <windows.h>
#include <stdio.h> 
using namespace std;

//贺镇涛
//打印帮助文件
void Text_print(string path)
{
#if defined _WIN32//实测:ubuntu不存在乱码问题，也没有chcp命令。
	system("chcp 65001");//用于解决中文乱码问题
#endif
	ifstream inf(path);
	string line;
	if (inf) //如果文件存在
	{
		while (getline(inf, line))
		{
			cout << line << endl;
		}
	}
	else printf("No such file or directory:%s.\n", path.c_str());//输出文件不存在的提示
	/*注：man_print()基于CSDN作者weixin_45699092的原创文章（有修改）。去除了多余的操作，在读取时直接输入，不需要引入vector<string>暂时保存，再循环输出；chcp65001用于解决windows默认环境下中文输出乱码的问题。原文及修改后的函数都遵循CC 4.0 BY - SA协议，转载注明：https ://blog.csdn.net/weixin_45699092/article/details/106946525*/
}

void shell(string command)
{
	system(command.c_str());
}
void Time()
{
	SYSTEMTIME sys;
	GetLocalTime(&sys);
	cout << sys.wYear << "年" << sys.wMonth << "月" << sys.wDay << "日" << sys.wHour << "时" << sys.wMinute << "分" << sys.wSecond << "秒" << endl;
}
void Mys()
{
	{
		SYSTEMTIME sys;
		GetLocalTime(&sys);
		ofstream outFile;
		//打开文件
		outFile.open("D:\\my.txt");
		string arr[4] = { "<*Content-type:application/mathtoys*>","<***Mathtoys Document-HongYi Honor College,WHU G2021***>","<Created by Mathtoys-v0.4","<Document/Begin>" };
		int i;
		for (i = 0; i < 4; i++)
		{
			//写入数据
			outFile << arr[i] << endl;
		}
		outFile << sys.wYear << "年" << sys.wMonth << "月" << sys.wDay << "日" << sys.wHour << "时" << sys.wMinute << "分" << sys.wSecond << "秒" << endl;
		//关闭文件
		outFile.close();
	}
}
string get_property(bool ShouldPrint = 1/*若为真，若为真，则向屏幕输出，否则仅返回*/)
{
	if (ShouldPrint == 1)
	{
		Time();
	}
	else
	{
		return 0;
	}
}
string readline(int k, bool ShouldPrint = 1/*若为真，则向屏幕输出，否则仅返回*/)
{
	ifstream in("my.txt"); //txt文件与源代码要在一个文件夹内
	string filename;
	string line;
	vector<string>  m_vec;
	if (in) // 有该文件
	{
		while (getline(in, line)) // line中不包括每行的换行符
		{
			m_vec.push_back(line); //读取每一行并
		}

		for (int i = 0; i < m_vec.size(); i++)
		{
			cout << m_vec[i] << endl; //把每一行的内容打印到屏幕上
		}

	}
	else // 没有该文件
	{
		cout << "no such file" << endl;
	}

	return 0;
}
